package com.ruoyi.basedata.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.basedata.domain.Phone;
import com.ruoyi.basedata.service.IPhoneService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 联系方式Controller
 * 
 * @author lvql
 * @date 2024-10-24
 */
@RestController
@RequestMapping("/phone")
public class PhoneController extends BaseController
{
    @Autowired
    private IPhoneService phoneService;

    /**
     * 查询联系方式列表
     */
    @RequiresPermissions("basedata:phone:list")
    @GetMapping("/list")
    public TableDataInfo list(Phone phone)
    {
        startPage();
        List<Phone> list = phoneService.selectPhoneList(phone);
        return getDataTable(list);
    }

    /**
     * 导出联系方式列表
     */
    @RequiresPermissions("basedata:phone:export")
    @Log(title = "联系方式", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Phone phone)
    {
        List<Phone> list = phoneService.selectPhoneList(phone);
        ExcelUtil<Phone> util = new ExcelUtil<Phone>(Phone.class);
        util.exportExcel(response, list, "联系方式数据");
    }

    /**
     * 获取联系方式详细信息
     */
    @RequiresPermissions("basedata:phone:query")
    @GetMapping(value = "/{Id}")
    public AjaxResult getInfo(@PathVariable("Id") Integer Id)
    {
        return success(phoneService.selectPhoneById(Id));
    }

    /**
     * 新增联系方式
     */
    @RequiresPermissions("basedata:phone:add")
    @Log(title = "联系方式", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Phone phone)
    {
        return toAjax(phoneService.insertPhone(phone));
    }

    /**
     * 修改联系方式
     */
    @RequiresPermissions("basedata:phone:edit")
    @Log(title = "联系方式", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Phone phone)
    {
        return toAjax(phoneService.updatePhone(phone));
    }

    /**
     * 删除联系方式
     */
    @RequiresPermissions("basedata:phone:remove")
    @Log(title = "联系方式", businessType = BusinessType.DELETE)
	@DeleteMapping("/{Ids}")
    public AjaxResult remove(@PathVariable Integer[] Ids)
    {
        return toAjax(phoneService.deletePhoneByIds(Ids));
    }
}
